﻿CREATE PROCEDURE [dbo].[proc_Order_Change_OrderItem_Hedge]
	(
		@Id int,
		@CId int
	)
AS
Begin
	Update [Order_Change] Set flag=1 Where Id=@CId And flag=0

	Insert into Order_Change_Item
	(
		CId,OId
		,ProductId
		,ProductName
		,UnitPrice
		,Quantity
		,Salesman
		,SalesmanAccount
		,DepId
		,CompanyId
		,CreateDate
		,Description
		,TradeDate
	)
	Select @CId,OId
		,ProductId
		,ProductName
		,0-UnitPrice
		,Quantity
		,Salesman
		,SalesmanAccount
		,DepId
		,CompanyId
		,GetDate()
		,'产品「'+ProductName+'」的对冲数据'
		,GetDate()
	From Order_Item Where Id=@Id
	
--	Select @je=Sum(UnitPrice) From Order_Item Where OId=@OId
--	Update [Order_Change] Set newje=@je Where OId=@OId
End